﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Douban.Api.Authorization
{
    public class QueryParameter : IComparable<QueryParameter>
    {
        public QueryParameter(string name, string value) : this(new[] { name, value }) {}

        public QueryParameter(IList<string> query)
        {
            if(query.Count != 2)
            {
                throw new ArgumentOutOfRangeException("query should have 2 elements");
            }

            this.Name = query[0];
            this.Value = query[1];
        }

        public string Name { get; protected set; }

        public string Value { get; protected set; }

        public int CompareTo(QueryParameter other)
        {
            return Name == other.Name ?
                string.Compare(Value, other.Value) :
                string.Compare(Name, other.Name);
        }

        public override string ToString()
        {
            return string.Format("{0}={1}", Name, Value);
        }
    }
}
